# TravisCI (https://travis-ci.org) configuration file
# https://docs.travis-ci.com/user/languages/python

# Note about PyQt related unit tests:
# They are not executed on architecture "ppc64le". For this architecture
# PyQt is not available from PyPi and not installable via pip.
# The alternative to use "system-site-packages" option and installing PyQt
# from Ubuntu repository via "apt" is not working as expected. TravisCI
# allow "system-site-packages" only for those Python interpreteres that are
# offered by Ubuntu itself; Python 3.8 in case of Ubuntu Focal. Other Python
# versions are installed from other sources into a virtual environment and
# not allowed to use packages installed via "apt".


os: linux
 
# ensures that we have UUID filesystem mounts for proper testing
dist: focal

language: python

arch:
 - amd64
 - ppc64le

python:
  - "3.8"
  - "3.9"
  - "3.10"
  - "3.11"
  - "3.12"
 
addons:
  # add localhost to known_hosts to prevent ssh unknown host prompt during unit tests
  ssh_known_hosts: localhost

env:
  # TravisCI support said this could prevent errors from "make".
  PYTHONUNBUFFERED=1
  
before_install:
  # disable mongodb as we don't need it and it sometimes temporary fails
  # https://github.com/travis-ci/travis-ci/issues/4937#issuecomment-149289729
  - sudo rm -f /etc/apt/sources.list.d/mongodb.list
  - sudo apt-get -qq update
  # install screen, and util-linux (provides flock) for test_sshtools
  - sudo apt-get install -y sshfs screen util-linux

jobs:
  exclude:
    - python: "3.9"
    - python: "3.10"
    - python: "3.11"
    # Excluding temporarily because Python 3.12 for ppc64le is not
    # available yet on Travis.
    - arch: ppc64le
      python: "3.12"

install:
  - pip install pylint coveralls pyfakefs keyring
  # PyQt is not available for "ppc64le" architecture on PyPi
  - if [ "$TRAVIS_ARCH" != "ppc64le" ] ; then pip install pyqt6 dbus-python; fi
  # add ssh public / private key pair to ensure user can start ssh session to localhost for tests
  - ssh-keygen -b 2048 -t rsa -f /home/travis/.ssh/id_rsa -N ""
  - cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
  # start ssh-agent so that we can add private keys
  - eval `ssh-agent -s`

script:
  # compile all files - ensure that syntax is correct
  - python -m compileall common common/test common/plugins qt qt/test qt/plugins
  # run unit tests - ensure that functionality is correct
  - cd common
  - ./configure  --python=python3
  - make unittest-v
  - cd ..
  - cd qt
  - ./configure --python=python3
  - make
  # PyQt is not installed on "ppc64le"
  - if [ "$TRAVIS_ARCH" != "ppc64le" ] ; then pytest ; else echo -e "\033[1;35mOn ppc64le no Qt testing because PyQt is impossible to install.\033[0m" ; fi

after_success:
  - coverage combine
  - coveralls
